package com.itheima.controller;

import com.itheima.aspect.Log;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.service.ClazzService;
import com.itheima.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*班级*/
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;


    /**
     * 添加班级
     *
     * @param clazz
     * @return
     */
    @Log
    @PostMapping()
    public Result addClazz(@RequestBody Clazz clazz) {
        clazzService.addClazz(clazz);
        return Result.success();
    }

    /**
     * 查询全部班级
     *
     * @return
     */
    @GetMapping("/list")
    public Result selectClazzs() {
        List<Clazz> clazzList = clazzService.selectClazzs();
        return Result.success(clazzList);
    }

    /**
     * 分页查询班级信息
     *
     * @param page
     * @return
     */
    @GetMapping
    public Result clazzPagequery(ClazzQueryParam page) {
        PageBean pageBean = clazzService.clazzPagequery(page);
        return Result.success(pageBean);
    }

    /**
     * 根据id查询班级
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getClazzById(@PathVariable Integer id) {
        Clazz clazz = clazzService.getClazzById(id);
        return Result.success(clazz);
    }

    /**
     * 修改班级信息
     *
     * @param clazz
     * @return
     */
    @Log
    @PutMapping
    public Result updateClazzById(@RequestBody Clazz clazz) {
        clazzService.updateClazzById(clazz);
        return Result.success();
    }

    /**
     * 删除班级
     *
     * @param id
     * @return
     */
    @Log
    @DeleteMapping("/{id}")
    public Result deleteClazz(@PathVariable Integer id) {
        clazzService.deleteClazz(id);
        return Result.success();
    }
}
